"""drop user_preferences table and remove indexes"""

from alembic import op
import sqlalchemy as sa


revision = "202510180004"
down_revision = "202510180003"
branch_labels = None
depends_on = None


def upgrade() -> None:
  try:
    op.drop_index("ix_user_preferences_relationship_id", table_name="user_preferences")
  except Exception:
    pass
  try:
    op.drop_index("ix_user_preferences_user_id", table_name="user_preferences")
  except Exception:
    pass
  try:
    op.drop_table("user_preferences")
  except Exception:
    pass


def downgrade() -> None:
  op.create_table(
    "user_preferences",
    sa.Column("id", sa.Integer(), primary_key=True, index=True),
    sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
    sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
    sa.Column("deleted_at", sa.DateTime(timezone=True), nullable=True),
    sa.Column("user_id", sa.Integer(), nullable=False),
    sa.Column("relationship_id", sa.Integer(), nullable=True),
    sa.Column("data_json", sa.JSON(), nullable=False),
  )
  op.create_index("ix_user_preferences_user_id", "user_preferences", ["user_id"], unique=False)
  op.create_index("ix_user_preferences_relationship_id", "user_preferences", ["relationship_id"], unique=False)

